package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.neusoft.elmboot.po.Orders;
import com.neusoft.elmboot.service.OrdersService;

@RestController
@RequestMapping("/Orders")
public class OrdersController {

	@Autowired
	private OrdersService ordersService;
	
	@PostMapping("/userId/{userId}/businessId/{businessId}/daId/{daId}/orderTotal/{orderTotal}")
	public int createOrders(Orders orders) throws Exception{
		return ordersService.createOrders(orders);
	}
	
	@GetMapping("/orderId/{orderId}")
	public Orders getOrdersById(Orders orders) throws Exception{
		return ordersService.getOrdersById(orders.getOrderId());
	}
	
	@GetMapping("/userId/{userId}")
	public List<Orders> listOrdersByUserId(Orders orders) throws Exception{
		return ordersService.listOrdersByUserId(orders.getUserId());
	}
	
	@PutMapping("/states/orderId/{orderId}")
	public int updateOrderStateByOrderId(Orders orders) throws Exception{
		return ordersService.updateOrderStateByOrderId(orders.getOrderId());
	}
	
	@GetMapping("/businessId/{businessId}")
	public List<Orders> listOrdersByBusinessId(Orders orders) throws Exception{
		return ordersService.listOrdersByBusinessId(orders.getBusinessId());
	}
}
